#include<unistd.h>
#include<time.h>
#include"thread.hpp"
#include"ringqueue.hpp"
#include"task.hpp"
#include"threadpool.hpp"

void* Consumer(void* args)
{
	ringqueue<task> *rq = static_cast<ringqueue<task> *>(args);
	while(1)
	{
		task tk;
		rq->pop(tk);
		tk();
		//cout<<"consume:"<<task<<endl;
		//sleep(1);
	};

};
void* Productor(void* args)
{
	ringqueue<task> *rq = static_cast<ringqueue<task> *>(args);
	while(1)
	{
		string name ="task"+to_string(rand()%10);
		task tk(name);
		rq->push(tk);
		//cout<<"process:"<<task<<endl;
	
	};

};
int main()
{
//	srand(time(nullptr));
//	ENABLEFILE("logtest.txt");
//
//	ringqueue<task> *rq = new ringqueue<task>(5);
//    pthread_t c1, c2, p1, p2, p3;
//    pthread_create(&c1, nullptr, Consumer, rq);
//    pthread_create(&c2, nullptr, Consumer, rq);
//    pthread_create(&p1, nullptr, Productor, rq);
//    pthread_create(&p2, nullptr, Productor, rq);
//    pthread_create(&p3, nullptr, Productor, rq);
//
//
//    pthread_join(c1, nullptr);
//    pthread_join(c2, nullptr);
//    pthread_join(p1, nullptr);
//    pthread_join(p2, nullptr);
//    pthread_join(p3, nullptr);
	for(int i =0;i<10;i++)
	{
	string name ="task-"+to_string(i);
	task tk(name);
	threadpool<task>::GetInstance()->push(tk);
	}
	//sleep(3);
	threadpool<task>::GetInstance()->stop();
	for(int i =10;i<20;i++)
	{
	string name ="task-"+to_string(i);
	task tk(name);
	threadpool<task>::GetInstance()->push(tk);
	}
	sleep(6);
	
    return 0;
}
